package SqlService;

/**
 * Created by ghost461 on 17-5-8.
 * Updated by codemaster on 17-6-29
 */

import DataService.*;
import java.sql.*;
import TimeService.*;

public class CURD {
	private Connection sqlGo;
	public CURD(){
		Sql sql = new Sql();
		sqlGo = sql.getCon();
	}
	public Boolean Insert(JsonBean jsonbean) {
		try {
			TimeProvider time = new TimeProvider();
			PreparedStatement sqlReady;
			String query = "insert into WifiObject.data(wifi,data,mmac,rate,time,lat,lon,timedata) values('"+jsonbean.id+"','"+jsonbean.data+"','"+jsonbean.mmac+"',"+jsonbean.rate+",'"+jsonbean.time+"','"+jsonbean.lat+"','"+jsonbean.lon+"','"+time.getTime()+"');";
			sqlReady = sqlGo.prepareStatement(query);
			if (sqlReady.executeUpdate() == 0)
				return false;
			System.out.println("写入成功");
			return true;
		} catch (SQLException e) {
			System.out.println("写入出错");
			e.printStackTrace();
		}
		return false;
	}
	public Boolean Insert2(JsonBean2 jsonbean) {
		try {
			//TimeProvider time = new TimeProvider();
			PreparedStatement sqlReady;
			String query = "insert into WifiObject.wifidata(mac,wifimac,rssi,ranges,times) values('"+jsonbean.mac+"','"+jsonbean.wifimac+"','"+jsonbean.rssi+"',"+jsonbean.ranges+",'"+jsonbean.times+"');";
			sqlReady = sqlGo.prepareStatement(query);
			if (sqlReady.executeUpdate() == 0)
				return false;
			System.out.println("写入成功");
			return true;
		} catch (SQLException e) {
			System.out.println("写入出错");
			e.printStackTrace();
		}
		return false;
	}
	
}

